#include "mbed.h"

#include "pid.h"
#define  delay_us  wait_us
#define uint unsigned int
#define uchar unsigned char
#define	TL	0
#define	TH	1
#define	ERR	2
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
PwmOut mypwm3(PC_9);//PC_9
PwmOut mypwm1(PA_15);//PC_9
PwmOut mypwm2(PB_7);//PC_9
Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut led1(LED1);

//DigitalOut mypin(PC_0);
DigitalOut mlx90614_SCL1(PB_3);
DigitalInOut mlx90614_SDA1(PA_10);
DigitalOut mlx90614_SCL2(PB_4);
DigitalInOut mlx90614_SDA2(PB_5);
DigitalOut mlx90614_SCL3(PA_8);
DigitalInOut mlx90614_SDA3(PB_10);

DigitalOut mlx90614_SCL4(PB_0);
DigitalInOut mlx90614_SDA4(PC_1);

Ticker pidTicker;
//Ticker filterTicker;
char tempH,tempL,err;


    



/**********************************************************************************************************
设置PWM输出函数
**********************************************************************************************************/
void setPWM(char chx,float Pwm)
{
	int pulse;
	pulse = Pwm * 10000;
	switch(chx)
	{
		case 1:mypwm1.pulsewidth_us(pulse);	break;
		case 2:mypwm2.pulsewidth_us(pulse);	break;
		case 3:mypwm3.pulsewidth_us(pulse);	break;
	}
}


//unsigned int max31865_adc_code;
//int t_pulsewidth=10,t_period=10,t_best_pulsewidth;
//double t_current;
/**********************************************************************************************************
定义PID结构体
**********************************************************************************************************/
	struct _PID{
	double Error0;
	double Error1;
	double Error2;
	double Pwm0;
	double Pwm1;
	double PidP;
	double PidI;
	double PidD;
	double SetT;
	char Channel;
	};
struct _PID spid1,spid2,spid3;
/**********************************************************************************************************
PID初始化函数
**********************************************************************************************************/
void PIDInit(void)
{
  spid1.Error0=0;
	spid1.Error1=0;
	spid1.Error2=0;
	spid1.Pwm0=0;
	spid1.Pwm1=0;
	spid1.PidP=0.1;
	spid1.PidI=0.0001;
	spid1.PidD=0.00005;
	spid1.SetT=120;
	spid1.Channel=1;
	
  spid2.Error0=0;
	spid2.Error1=0;
	spid2.Error2=0;
	spid2.Pwm0=0;
	spid2.Pwm1=0;
	spid2.PidP=0.1;
	spid2.PidI=0.0005;
	spid2.PidD=0.001;
	spid2.SetT=120;
	spid2.Channel=2;	
	
  spid3.Error0=0;
	spid3.Error1=0;
	spid3.Error2=0;
	spid3.Pwm0=0;
	spid3.Pwm1=0;
	spid3.PidP=0.1;
	spid3.PidI=0.0001;
	spid3.PidD=0.002;
	spid3.SetT=120;
	spid3.Channel=3;
}
/**********************************************************************************************************
PID 各个参数设置，温度设置函数
**********************************************************************************************************/
void PIDSingleSet(struct _PID *spid,char kx,uint kdata)//pid控制 pid设置，c周期设置 t温度设置
{
	double kdata_tmp=0;
	kdata_tmp=kdata/1000000.0;
		switch(kx)
		{
			case 	'p':	spid->PidP=kdata_tmp;break;
			case 	'i':	spid->PidI=kdata_tmp;break;
			case 	'd':	spid->PidD=kdata_tmp;break;
			case	't':	spid->SetT=kdata;break;
			
		}
//		pc.printf("%c%d %f\r\n",kx,spid->Channel,kdata_tmp);
		return;
}
/**********************************************************************************************************
PID控制函数
**********************************************************************************************************/
float getIrTemp(uchar chx);
float PIDCtrl(struct _PID *spid,float cTemp=0)	
{	
//	double cTemp=0;
//	cTemp=getIrTemp(spid->Channel);
	spid->Error0 = spid->SetT - cTemp;
//	if(spid->Channel==2)
//	{
//		pc.printf("ct6 %f\n\r", spid->Error0 );
//	}
//	switch(spid->Channel)
//	{
//		case 1:	pc.printf("current_temp1 %f\n\r", spid->Error0 );
//						break;
//		case 2:	pc.printf("current_temp2 %f\n\r", spid->Error0 );
//						break;
//		case 3:	pc.printf("current_temp3 %f\n\r", spid->Error0 );	
//						break;
//	}	
	
	//spid->Pwm0	 = spid->Pwm1 + (spid->PidP + spid->PidI)* spid->Error0 - spid->PidP * spid->Error1;	//原PID计算公式
	//Pwm0	 = Pwm1 + (PidP + PidI+PidD)* Error0 -(PidP + 2*PidD)* Error1+ PidD*Error2; //原 PI 计算公式
	spid->Pwm0	 = spid->Pwm1 + (spid->PidP + spid->PidI+ spid->PidD)* spid->Error0 - (spid->PidP+2*spid->PidD) * spid->Error1+spid->PidD*spid->Error2;
	spid->Error1 = spid->Error0;
	spid->Error2 = spid->Error1;

	if(spid->Pwm0 >1)
		spid->Pwm0 =1;
	else if (spid->Pwm0 <0)
		spid->Pwm0 = 0;		
	spid->Pwm1 = spid->Pwm0;
	setPWM(spid->Channel,spid->Pwm1);
	return spid->Pwm1;
}
/**********************************************************************************************************
PID参数串口输出打印函数
**********************************************************************************************************/
uchar pidSetFlag=0;
void pidPrint(void)
{
		pc.printf("p1 %f\r\n",spid1.PidP);
		pc.printf("i1 %f\r\n",spid1.PidI);
		pc.printf("d1 %f\r\n",spid1.PidD);
		pc.printf("t1 %f\r\n",spid1.SetT);
		pc.printf("p2 %f\r\n",spid2.PidP);
		pc.printf("i2 %f\r\n",spid2.PidI);
		pc.printf("d2 %f\r\n",spid2.PidD);
		pc.printf("t2 %f\r\n",spid2.SetT);
		pc.printf("p3 %f\r\n",spid3.PidP);
		pc.printf("i3 %f\r\n",spid3.PidI);
		pc.printf("d3 %f\r\n",spid3.PidD);
		pc.printf("t3 %f\r\n",spid3.SetT);
		return;	
}
/**********************************************************************************************************
mls90614 初始化函数
**********************************************************************************************************/
void mlx90614_init()              //初始化
{
	mlx90614_SDA1.output(); 
	mlx90614_SDA2.output(); 
	mlx90614_SDA3.output(); 
	mlx90614_SDA4.output(); 
	
	mlx90614_SCL1=1;
	mlx90614_SCL2=1;
	mlx90614_SCL3=1;
	mlx90614_SCL4=1;
//		delay_us(2);
	
	mlx90614_SCL1=0;  //切换到SMBUS模式
	mlx90614_SCL2=0;  //切换到SMBUS模式
	mlx90614_SCL3=0;  //切换到SMBUS模式
	mlx90614_SCL4=0;  //切换到SMBUS模式
//		delay_us(150); 
	mlx90614_SCL1=1;
	mlx90614_SCL2=1;
	mlx90614_SCL3=1;
	mlx90614_SCL4=1;
//		delay_us(2);	
	mlx90614_SDA1=1;
	mlx90614_SDA2=1;
	mlx90614_SDA3=1;
	mlx90614_SDA4=1;
//		delay_us(2);
}
/**********************************************************************************************************
mls90614 开始函数
**********************************************************************************************************/
void mlx90614_start()         //启动信号
{
	mlx90614_SDA1.output(); 
	mlx90614_SDA2.output(); 
	mlx90614_SDA3.output();
	mlx90614_SDA4.output();
	
	mlx90614_SCL1=0;
	mlx90614_SCL2=0;
	mlx90614_SCL3=0;
	mlx90614_SCL4=0;
////		 delay_us(2);
	mlx90614_SDA1=1;
	mlx90614_SDA2=1;
	mlx90614_SDA3=1;
	mlx90614_SDA4=1;
//		 delay_us(2);	
	mlx90614_SCL1=1;
	mlx90614_SCL2=1;
	mlx90614_SCL3=1;
	mlx90614_SCL4=1;
//		 delay_us(2);
	mlx90614_SDA1=0;
	mlx90614_SDA2=0;
	mlx90614_SDA3=0;
	mlx90614_SDA4=0;
//		 delay_us(2);
////		mlx90614_SCL=0;
////		 delay_us(2);	
}
/**********************************************************************************************************
mls90614 停止函数
**********************************************************************************************************/
void mlx90614_stop()            //停止信号
{
	mlx90614_SDA1.output(); 
	mlx90614_SDA2.output();
	mlx90614_SDA3.output();
	mlx90614_SDA4.output();
	
  mlx90614_SCL1=0;
	mlx90614_SCL2=0;
	mlx90614_SCL3=0;
	mlx90614_SCL4=0;
 //     delay_us(2);
	mlx90614_SDA1=0;
	mlx90614_SDA2=0;
	mlx90614_SDA3=0;
	mlx90614_SDA4=0;
 //    delay_us(2);

	mlx90614_SCL1=1;
	mlx90614_SCL2=1;
	mlx90614_SCL3=1;
	mlx90614_SCL4=1;
//     delay_us(2);/////////

	mlx90614_SDA1=1;
	mlx90614_SDA2=1;
	mlx90614_SDA3=1;
	mlx90614_SDA4=1;
 //    delay_us(2);
}
/**********************************************************************************************************
mls90614 字节发送函数
**********************************************************************************************************/
void mlx90614_sendbyte(uchar data)  //       写一个字节
{
	uchar i;  
	mlx90614_SDA1.output();
	mlx90614_SDA2.output();	
	mlx90614_SDA3.output();
	mlx90614_SDA4.output();	
	for(i=0;i<8;i++)
	{  

		mlx90614_SCL1=0;
		mlx90614_SCL2=0;
		mlx90614_SCL3=0;
		mlx90614_SCL4=0;
//	 delay_us(2);

		if((data<<i)&0x80)
		{
							mlx90614_SDA1.write(1);
							mlx90614_SDA2.write(1);
							mlx90614_SDA3.write(1);
							mlx90614_SDA4.write(1);
//			delay_us(2);
		} else if(((data<<i)&0x80)==0)
		{
							mlx90614_SDA1.write(0);
							mlx90614_SDA2.write(0);
							mlx90614_SDA3.write(0);
							mlx90614_SDA4.write(0);
//			delay_us(2);
		}
//delay_us(2);
		mlx90614_SCL1=1;
		mlx90614_SCL2=1;
		mlx90614_SCL3=1;
		mlx90614_SCL4=1;
//		delay_us(2);

	}

}
/**********************************************************************************************************
mlx90614 读取响应函数
**********************************************************************************************************/
void  read_ack()
{

	mlx90614_SCL1=0;
	mlx90614_SCL2=0;
	mlx90614_SCL3=0;
	mlx90614_SCL4=0;
//	delay_us(2);
	mlx90614_SDA1.output();
	mlx90614_SDA2.output();
	mlx90614_SDA3.output();
	mlx90614_SDA4.output();
	
	mlx90614_SDA1=0;
	mlx90614_SDA2=0;
	mlx90614_SDA3=0;
	mlx90614_SDA4=0;
 // delay_us(2); 
	mlx90614_SCL1=1;
	mlx90614_SCL2=1;
	mlx90614_SCL3=1;
	mlx90614_SCL4=1;
//  delay_us(2);
	mlx90614_SCL1=0;
	mlx90614_SCL2=0;
	mlx90614_SCL3=0;
	mlx90614_SCL4=0;
//  delay_us(2); 
	
}

/**********************************************************************************************************
mlx90614 字节读取函数
**********************************************************************************************************/
uchar  bit_buf1=0,bit_buf2=0,bit_buf3=0,bit_buf4=0;
uchar tempL1,tempL2,tempL3,tempL4,tempH1,tempH2,tempH3,tempH4,err1,err2,err3,err4;

void mlx90614_readbyte(uchar HLR)
{
  uchar i;
			
	mlx90614_SDA1.input();  
	mlx90614_SDA2.input();  
	mlx90614_SDA3.input();
	mlx90614_SDA4.input();  
	for(i=0;i<8;i++)
	{  
	 
		mlx90614_SCL1=0;
		mlx90614_SCL2=0;
		mlx90614_SCL3=0;
		mlx90614_SCL4=0;
//		mlx90614_SCL4=0;
//		delay_us(1);

		mlx90614_SCL1=1;
		mlx90614_SCL2=1;
		mlx90614_SCL3=1;
		mlx90614_SCL4=1;
//		delay_us(2);
		switch(HLR)
		{
			case	0:tempL1<<=1;tempL2<<=1;tempL3<<=1;tempL4<<=1;
							bit_buf1=mlx90614_SDA1.read();	
							bit_buf2=mlx90614_SDA2.read();	
							bit_buf3=mlx90614_SDA3.read();	
							bit_buf4=mlx90614_SDA4.read();
							tempL1+=bit_buf1;tempL2+=bit_buf2;tempL3+=bit_buf3;tempL4+=bit_buf4;
			
							break;
			case	1:tempH1<<=1;tempH2<<=1;tempH3<<=1;tempH4<<=1;
							bit_buf1=mlx90614_SDA1.read();	
							bit_buf2=mlx90614_SDA2.read();	
							bit_buf3=mlx90614_SDA3.read();
							bit_buf4=mlx90614_SDA4.read();
							tempH1+=bit_buf1;tempH2+=bit_buf2;tempH3+=bit_buf3;	tempH4+=bit_buf4;			
							break;
			case	2:err1<<=1,err2<<=1,err3<<=1,err4<<=1;
							bit_buf1=mlx90614_SDA1.read();	
							bit_buf2=mlx90614_SDA2.read();	
							bit_buf3=mlx90614_SDA3.read();	
							bit_buf4=mlx90614_SDA4.read();
							err1+=bit_buf1;err2+=bit_buf2;err3+=bit_buf3;err4+=bit_buf4;
							break;
		}
		


//		delay_us(2);
	}
		

}
/**********************************************************************************************************
发送响应函数
**********************************************************************************************************/
void send_ack(void)
{
	int i=0;
	mlx90614_SCL1=0;
	mlx90614_SCL2=0;
	mlx90614_SCL3=0;
	mlx90614_SCL4=0;
//	delay_us(2);
	
	mlx90614_SDA1=0;
	mlx90614_SDA2=0;
	mlx90614_SDA3=0;
	mlx90614_SDA4=0;
	
	mlx90614_SDA1.input();	
	mlx90614_SDA2.input();
	mlx90614_SDA3.input();
	mlx90614_SDA4.input();

//	delay_us(2);
	mlx90614_SCL1=1; 
	mlx90614_SCL2=1; 
	mlx90614_SCL3=1;
	mlx90614_SCL4=1;	
//	delay_us(2);
	
	mlx90614_SCL1=0;
	mlx90614_SCL2=0;
	mlx90614_SCL3=0;
	mlx90614_SCL4=0;
//	delay_us(2);	
	
//	while((0==mlx90614_SDA1.read())&&(i++<10))
//	{};	
//	while((0==mlx90614_SDA2.read())&&(i++<10))
//	{};	
//	while((0==mlx90614_SDA3.read())&&(i++<10))
//	{};	
	while((0==mlx90614_SDA4.read())&&(i++<10))
	{};	
//	delay_us(2);
}

/**********************************************************************************************************
mlx90614温度读取函数
**********************************************************************************************************/

void readTempType(uchar add)
{

  mlx90614_start();
  mlx90614_sendbyte(0x00);  //元件地址
  send_ack();
  mlx90614_sendbyte(add);   //寄存器地址
  send_ack(); 
  mlx90614_start();					
  mlx90614_sendbyte(0x01);	//读命令
  send_ack();
  mlx90614_readbyte(TL);
  read_ack();
  mlx90614_readbyte(TH);
  read_ack();
  mlx90614_readbyte(ERR);
  read_ack();
  mlx90614_stop();
//  return((tempH*256+tempL)/50.0-273.15);
}
/**********************************************************************************************************
获取红外温度函数
**********************************************************************************************************/
float IrTemp;
float getIrTemp(uchar chx)//获取红外温度 chx:通道序号
{
	switch(chx)
	{
		case 1:IrTemp=(tempH1*256+tempL1)/50.0-273.15;break;
		case 2:IrTemp=(tempH2*256+tempL2)/50.0-273.15;break;
		case 3:IrTemp=(tempH3*256+tempL3)/50.0-273.15;break;
		case 4:IrTemp=(tempH4*256+tempL4)/50.0-273.15;break;
	}
	return IrTemp;
}





/**********************************************************************************************************
滤波结构体
**********************************************************************************************************/
struct _FILTER{
float AA;
float BB;
float Tn;
float	To;
float tn;
float	to;
uint number;
};
struct _FILTER filter1,filter2,filter3,filter4;

void filterInit()
{
	filter1.AA=0.999;
	filter1.BB=0.001;
	filter1.Tn=0;
	filter1.To=0;
	filter1.tn=0;
	filter1.to=0;
	filter1.number=1;
	
	filter2.AA=0.999;
	filter2.BB=0.001;
	filter2.Tn=0;
	filter2.To=0;
	filter2.tn=0;	
	filter2.to=0;
	filter2.number=2;
	
	filter3.AA=0.999;
	filter3.BB=0.001;
	filter3.Tn=0;
	filter3.To=0;
	filter3.tn=0;
	filter3.to=0;
	filter3.number=3;
	
	filter4.AA=0.999;
	filter4.BB=0.001;
	filter4.Tn=0;
	filter4.To=0;
	filter4.tn=0;
	filter4.to=0;
	filter4.number=4;
}

float filterCalc(struct _FILTER *pfilter,float temp)
{
		pfilter->To = pfilter->Tn;
		pfilter->to = pfilter->tn;
		pfilter->Tn = temp;
		pfilter->tn = (pfilter->To) * (pfilter->BB) + (pfilter->to) * (pfilter->AA);
		return pfilter->tn;
}

/**********************************************************************************************************
滤波中断处理函数
**********************************************************************************************************/
DigitalOut test_pin(PC_5);
uchar tempFlag=0;
float tempBuf1,tempBuf2,tempBuf3,tempBuf4;
void filterHandler()
{
	test_pin=1;
	readTempType(0x07);

	filterCalc(&filter1,getIrTemp(1));
	filterCalc(&filter2,getIrTemp(2));	
	filterCalc(&filter3,getIrTemp(3));	
	filterCalc(&filter4,getIrTemp(4));
	if(tempFlag==0)
	{
		tempBuf1=filter1.Tn;
		tempBuf2=filter2.tn;
		tempBuf3=filter3.Tn;
		tempBuf4=filter4.Tn;
		tempFlag=1;
	}
//				pc.printf("current_temp1 %f\n\r", filter1.Tn);
//				pc.printf("current_temp2 %f\n\r", filter2.Tn);
//				pc.printf("current_temp3 %f\n\r", filter3.Tn);	
//				pc.printf("temp7 %f\n\r",filter4.Tn);	//红外温度1滤波后温度打印	
	test_pin=0;
}

/**********************************************************************************************************
pid处理中断函数
**********************************************************************************************************/
DigitalOut test_pin1(PC_6);

char led1Flag=0,tickerFlag=0,pidProFlag=0;

void pidHandler()
{
	readTempType(0x07);
//		tickerFlag=1;
//		led1Flag=(led1Flag==0?1:0);
//		led1=((led1Flag&0x01)?1:0);
		test_pin1=1;
//		PIDCtrl(&spid1,filter1.tn);
//		PIDCtrl(&spid2,filter2.tn);
//		PIDCtrl(&spid3,filter3.tn);
	
		PIDCtrl(&spid1,getIrTemp(1));
		PIDCtrl(&spid2,getIrTemp(2));
		PIDCtrl(&spid3,getIrTemp(3));
		test_pin1=0;
		pidProFlag=1;
}
/**********************************************************************************************************
串口pid设置中断处理函数
**********************************************************************************************************/
float pidCycle=0.1,filterCycle=0.01;
uchar pidCycleFlag=0,filterCycleFlag=0;
char cmd_tmp,no_tmp,getc_tmp,number_tmp;
unsigned char	rstate=0;
unsigned int data_tmp=0;
void echouart()
{
//	filterTicker.detach();
	pidTicker.detach();
	switch(rstate)
	{
		case	0: 	cmd_tmp=pc.getc();
							if(cmd_tmp=='p'||cmd_tmp=='i'||cmd_tmp=='d'||cmd_tmp=='t'||cmd_tmp=='c'||cmd_tmp=='r'||cmd_tmp=='f')//t 温度；c 采样周期
								rstate=1;
							else rstate=0;						
		case	1:  no_tmp=pc.getc();
							if((no_tmp=='1'||no_tmp=='2'||no_tmp=='3')&&(cmd_tmp=='p'||cmd_tmp=='i'||cmd_tmp=='d'||cmd_tmp=='t'))
							{
								number_tmp=no_tmp;
								rstate=2;
							}else if(no_tmp==' ')
							{
								rstate=3;
							}
							else rstate=0;
							break;
		case 	2:	if(pc.getc()==' ')
								rstate=3;
							else rstate=0;
							break;
		case	3:	getc_tmp=pc.getc();
							if(getc_tmp>='0'&&getc_tmp<='9')
							{
									data_tmp=data_tmp*10+(getc_tmp-'0');
									rstate=3;
							}else if(getc_tmp=='\r')
							{
								rstate=4;
							}else rstate=0;
							break;
		case	4: 	getc_tmp=pc.getc();
							if(getc_tmp=='\n')
							{
								if(cmd_tmp=='p'||cmd_tmp=='i'||cmd_tmp=='d'||cmd_tmp=='t')
								{
									
									switch(number_tmp)
									{
										case '1':	PIDSingleSet(&spid1,cmd_tmp,data_tmp);break;  // cmd_tmp:命令字符，如‘p’；data_tmp:参数值
										case '2':	PIDSingleSet(&spid2,cmd_tmp,data_tmp);break;
										case '3':	PIDSingleSet(&spid3,cmd_tmp,data_tmp);break;
									}
									pidSetFlag=1;
									
								}
								if(cmd_tmp=='c')
								{
									pidCycle=data_tmp/1000.0;
									pidCycleFlag=1;
								
								}
								if(cmd_tmp=='f')
								{
									filterCycle=data_tmp/1000.0;
									filterCycleFlag=1;
								
								}
								if(cmd_tmp=='r')
								{
									pidSetFlag=1;
									pidCycleFlag=1;
									filterCycleFlag=1;
								}
							//	pc.printf("%c%c %f\r\n",cmd_tmp,no_tmp,data_tmp/1000000.0);
								data_tmp=0;
							}
							rstate=0;
							break;
		
	}
	while(pc.readable())
	{
		pc.getc();
	}	
	pidTicker.attach(&pidHandler,pidCycle);	
//	filterTicker.attach(&filterHandler,filterCycle);	
}

/**********************************************************************************************************
主函数
**********************************************************************************************************/

int main() 
{
	mlx90614_init(); //
	pidPrint();
	filterInit();

	mypwm1.period_us(10000);
	mypwm2.period_us(10000);
	mypwm3.period_us(10000);
	PIDInit();
	pc.baud(9600);
	pc.attach(&echouart,SerialBase::RxIrq);  //定义串口接收中断
	pidTicker.attach(&pidHandler,pidCycle);				//定义PID处理中断;
//	filterTicker.attach(&filterHandler,filterCycle);	
  while(1) 
  {


			if(pidSetFlag)		//PID 参数打印，每设置一次打印一次。
			{

				pidSetFlag=0;
				pidPrint();

			}
			if(pidCycleFlag)   //PID 周期设置
			{

				pidCycleFlag=0;			
				pidTicker.attach(&pidHandler,pidCycle);
				
				pc.printf("%c %f \r\n",'c',pidCycle);

			//	pidPrint();
			}
			if(filterCycleFlag)   //PID 周期设置
			{
				filterCycleFlag=0;			
			//	filterTicker.attach(&filterHandler,filterCycle);			
				pc.printf("%c %f \r\n",'f',filterCycle);
			
			}			
//			if(tickerFlag)		//  每pidCycle时间 执行一次pid运算 
//			{
//				tickerFlag=0;
//				PIDCtrl(&spid1,filter1.tn);
//				PIDCtrl(&spid2,filter2.tn);
//				PIDCtrl(&spid3,filter3.tn);
//			}
				if(pidProFlag)
				{
					
					pc.printf("ct1 %f\n\r",getIrTemp(1));
					pc.printf("ct2 %f\n\r", getIrTemp(2));
					pc.printf("ct3 %f\n\r", getIrTemp(3));		
					pc.printf("ct4 %f\n\r",getIrTemp(4));	//红外温度1滤波后温度打印
					
					pidProFlag=0;
				}
				pc.printf("ct6 %f\n\r", spid1.Pwm0 );
			//	pc.printf("ct1 %f\n\r",spid2.Error0);
			//	pc.printf("ct2 %f\n\r", spid2.Error1);

	//		pc.printf("temp6 %f\n\r",filter1.Tn);	//红外温度2滤波前温度打印


			
//			test_pin=1;
//			readTempType(0x07);
//			pc.printf("t1 %f\n\r",(tempH1*256+tempL1)/50.0-273.15);	//红外温度1滤波后温度打印
//			pc.printf("t2 %f\n\r",(tempH2*256+tempL2)/50.0-273.15);	//红外温度1滤波后温度打印
//			pc.printf("t3 %f\n\r",(tempH3*256+tempL3)/50.0-273.15);	//红外温度1滤波后温度打印
//			pc.printf("t4 %f\n\r",(tempH4*256+tempL4)/50.0-273.15);	//红外温度1滤波后温度打印
//			test_pin=0;
	}
}

 
